// packageI/ecosphere_watercooler/water_use/components/bind/bind.js
const app = getApp();
Component({
  properties: {
    device_no:{
      type:String
    },
    mini_url: {
      type: String
    },
    course_name:{
      type:String
    }
  },
  data: {
    number: "",
    account: "",
    show: false,
  },
  lifetimes:{
    ready(){
      this.get_detail()
    },
  },
  /**
   * 组件的方法列表
   */
  methods: {
    get_detail(){
      app._getNetWork({
        url:app.getNetAddresss('plugin.water-machine.frontend.consumer.device.show'),
        data:{
          device_no:this.data.device_no
        },
        success:resdata=>{
          let {result,data} = resdata.data;
          if(result){
            console.log(data);
            this.setData({account:data.belongs_to_merchant.account})
          }
        }
      })
    },
  
    goto(){
      wx.navigateTo({
        url: '/packageI/ecosphere_watercooler/water_use/no_card/no_card?device_no='+this.data.device_no,
      })
    },
    show_dialog() {
      this.setData({
        show: true
      })
    },
    onClose() {
      this.setData({
        show: false
      })
    },
    onInput(e) {
      this.setData({
        number: e.detail.value
      })
    },
    accountInput(e) {
      this.setData({
        account: e.detail.value
      })
    },
    course(){
      wx.navigateTo({
        url: this.properties.mini_url,
      })
    },
    confirm() {
      app._postNetWork({
        url: app.getNetAddresss("plugin.water-machine.frontend.consumer.member-card.bind"),
        data: {
          card_no: this.data.number,
          account: this.data.account
        },
        success: resdata => {
          let {
            result,
            msg
          } = resdata.data;
          app.tips(msg);
          if (result) {
            this.setData({
              show: false
            });
            wx.navigateTo({
              url: '/packageI/ecosphere_watercooler/water_use/card/card',
            })
          }
        }
      })

    },
  }
})